﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace XGame.Animation
{

    /// <summary>
    /// The EntityBase class contains a single entity that the XGame library exposes to the end users.
    /// An entity contains a simple animation object internally that allows for a Sprite Sheet to
    /// be loaded in and manipulated; allowing for adjustments to the animation speed, frame sizes
    /// and other properties.
    /// 
    /// The entity class is declared as abstract so that it can be inherited on a per-use basis for
    /// any programmer to utilize.
    /// </summary>
    public abstract class EntityBase : XDraw
    {

        /// <summary>
        /// The animation object contains all internal calls and references to handle simplistic animation
        /// </summary>
        public SimpleAnimation2D Animation { get; protected set; }

        /// <summary>
        /// This represents the top-left corner of the entity's rectangle
        /// </summary>
        public Point Location { get; set; }

        /// <summary>
        /// The overlay color of this entity.
        /// </summary>
        public Color Overlay { get; set; }

        public virtual void Draw(SpriteBatch aSpriteBatch)
        {
            
            // Start drawing the entity at the proper location
            aSpriteBatch.Draw(
                Animation.Texture,
                new Rectangle(
                    Location.X,
                    Location.Y,
                    Animation.Reference.Width,
                    Animation.Reference.Height
                ),
                Animation.Frame,
                Overlay
            );

        }
        public virtual void Update(GameTime aTime)
        {
            Animation.Update(aTime);
        }
        public virtual void Initialize()
        {
            Animation.Initialize();
        }

    }

    /// <summary>
    /// The Entity class is an implementation of the EntityBase object
    /// </summary>
    public class Entity : EntityBase
    {

        /// <summary>
        /// Creates a new instance of the entity class with a Texture and Rectangle as requirements
        /// </summary>
        /// <param name="aSpriteSheet">The sprite sheet that contains the frames for the animation</param>
        /// <param name="aFrameSize">The size of each individual frame</param>
        public Entity(Texture2D aSpriteSheet, Rectangle aFrameSize)
        {
            Animation = new SimpleAnimation2D(aSpriteSheet, aFrameSize);
            Location = new Point(0, 0);
        }

    }

}
